package com.ruoyi.project.system.info.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.info.domain.BaseFamilyMemberInfo;
import com.ruoyi.project.system.info.service.IBaseFamilyMemberInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-02-18
 */
@Controller
@RequestMapping("/system/info2")
public class BaseFamilyMemberInfoController extends BaseController
{
    private String prefix = "system/info2";

    @Autowired
    private IBaseFamilyMemberInfoService baseFamilyMemberInfoService;

    @RequiresPermissions("system:info2:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info2";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:info2:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseFamilyMemberInfo baseFamilyMemberInfo)
    {
        startPage();
        List<BaseFamilyMemberInfo> list = baseFamilyMemberInfoService.selectBaseFamilyMemberInfoList(baseFamilyMemberInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:info2:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseFamilyMemberInfo baseFamilyMemberInfo)
    {
        List<BaseFamilyMemberInfo> list = baseFamilyMemberInfoService.selectBaseFamilyMemberInfoList(baseFamilyMemberInfo);
        ExcelUtil<BaseFamilyMemberInfo> util = new ExcelUtil<BaseFamilyMemberInfo>(BaseFamilyMemberInfo.class);
        return util.exportExcel(list, "info2");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:info2:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseFamilyMemberInfo baseFamilyMemberInfo)
    {
        return toAjax(baseFamilyMemberInfoService.insertBaseFamilyMemberInfo(baseFamilyMemberInfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BaseFamilyMemberInfo baseFamilyMemberInfo = baseFamilyMemberInfoService.selectBaseFamilyMemberInfoById(id);
        mmap.put("baseFamilyMemberInfo", baseFamilyMemberInfo);
        return prefix + "/edit";
    }

    /**
     * 查看页面，就是编辑页面所有input框无法编辑
     */
    @GetMapping("/check/{id}")
    public String check(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BaseFamilyMemberInfo baseFamilyMemberInfo = baseFamilyMemberInfoService.selectBaseFamilyMemberInfoById(id);
        mmap.put("baseFamilyMemberInfo", baseFamilyMemberInfo);
        return prefix + "/check";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:info2:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseFamilyMemberInfo baseFamilyMemberInfo)
    {
        return toAjax(baseFamilyMemberInfoService.updateBaseFamilyMemberInfo(baseFamilyMemberInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:info2:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseFamilyMemberInfoService.deleteBaseFamilyMemberInfoByIds(ids));
    }
}
